package com.gs.study.rabbitmq.send;

import java.util.Date;
import java.util.UUID;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.support.CorrelationData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.gs.study.domain.p.User;

@Component
public class Sender {

	@Autowired
	//private AmqpTemplate rabbitTemplate;
    private RabbitTemplate rabbitTemplate;

	
	public void sendDirect() {
        CorrelationData correlationId = new CorrelationData(UUID.randomUUID().toString());
        
		String context = "direct" + new Date();
		this.rabbitTemplate.convertAndSend("direct", "direct",context,correlationId);
	}

	public void send() {
        CorrelationData correlationId = new CorrelationData(UUID.randomUUID().toString());

		String context = "hello " + new Date();
		this.rabbitTemplate.convertAndSend("hello", "hello",context,correlationId);
	}
	
	public void fanoutExchangeSend() {
		User user = new User("张三", 24);
		/*this.rabbitTemplate.convertAndSend("fanoutExchange","abcd.ee","--------------");
		this.rabbitTemplate.convertAndSend("fanoutExchange","abcd.aa","==============");*/
		this.rabbitTemplate.convertAndSend("fanoutExchange","abcd.ee",user);
	}
	
	public void topicExchangeSend() {
		this.rabbitTemplate.convertAndSend("exchange", "topic.message", "topic.message");
		this.rabbitTemplate.convertAndSend("exchange", "topic.messages", "topic.messages");
	}




}